const sequelize = require("./db");
const { DataTypes } = require("sequelize");
const Category = require("./Category");

const Product = sequelize.define(
    "Product",
    {
        product_id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      product_name: {
        type: DataTypes.STRING(100),
        allowNull: false,
      },
      category_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          // 这是对另一个模型的参考
          model: Category,
          // 这是引用模型的列名
          key: 'category_id',
        
        }
      },
      product_title: {
        type: DataTypes.STRING(30),
        allowNull: false,
      },
      product_intro: {
        type: DataTypes.TEXT,
        allowNull: false,
      },
      product_picture: {
        type: DataTypes.STRING(200),
      },
      product_price: {
        type: DataTypes.DOUBLE,
        allowNull: false,
      },
      product_selling_price: {
        type: DataTypes.DOUBLE,
        allowNull: false,
      },
      product_num: {
        type: DataTypes.INTEGER,
        allowNull: false,
      },
      product_sales: {
        type: DataTypes.INTEGER,
        allowNull: false,
      },
      
    },
    {  
      timestamps: false
    }
)
module.exports = Product;